//获取本地购物车信息
//var buyCar = localStorage.buyCar;
//buyCar = eval('(' + buyCar + ')');
//加入购物车
function goodsAdd(id, num, gid, size, color, models, spec, changeArry) {
	var buyCar;
	if (localStorage.buyCar == null || localStorage.buyCar == "undefined" || readDataBuyCar(localStorage.buyCar) == "") {
		buyCar = {};
	} else {
		buyCar = readDataBuyCar(localStorage.buyCar);
		buyCar = eval('(' + buyCar + ')');
	}
	if (buyCar[gid] == "" || buyCar[gid] == null || buyCar[gid] == "undefined") {
		//购物车不存在,商品直接加入购物车
		buyCar[gid] = [{
			id : id,
			number : num,
			specColorpr : color,
			specSizepr : size,
			specModel : models,
			specSpec : spec
		}];
	} else {
		var buyCarGuide = buyCar[gid];
		var flag = 0;
		//遍历购物车，查看商品是否存在（同型号同颜色同尺码同规格）
		for (x in buyCarGuide) {
			var jsonObj = buyCarGuide[x];
			if (jsonObj.specSizepr) {
				ysize = jsonObj.specSizepr
			} else {
				ysize = ''
			}
			if (jsonObj.specColorpr) {
				ycolor = jsonObj.specColorpr
			} else {
				ycolor = ''
			}
			if (jsonObj.specModel) {
				ymodel = jsonObj.specModel
			} else {
				ymodel = ''
			}
			if (jsonObj.specSpec) {
				yspec = jsonObj.specSpec
			} else {
				yspec = ''
			}
			///////
			if (color) {
				ccolor = color
			} else {
				ccolor = ''
			}
			if (size) {
				csize = size
			} else {
				csize = ''
			}
			if (models) {
				cmodels = models
			} else {
				cmodels = ''
			}
			if (spec) {
				cspec = spec
			} else {
				cspec = ''
			}
			if (jsonObj.id == id && ysize == csize && ycolor == ccolor && ymodel == cmodels && yspec == cspec) {
				if (changeArry) {
					jsonObj["changeIdList"] = changeArry;
				} else {
					var onum = parseFloat(jsonObj.number);
					var nnum = onum + parseFloat(num);
					jsonObj['number'] = nnum;
				}
				flag = 1;

			}
		}
		//不存在直接添加商品
		if (flag == 0) {
			buyCarGuide.push({
				id : id,
				number : num,
				specColorpr : color,
				specSizepr : size,
				specModel : models,
				specSpec : spec
			});
		}
	}
	//更新本地购物车信息
	localStorage.buyCar = writeDataBuyCar(JSON.stringify(buyCar));
}

//调整数量：更新商品数量。
function goodsNum(id, gid, num, size, color, models, spec) {
	buyCar = readDataBuyCar(localStorage.buyCar);
	buyCar = eval('(' + buyCar + ')');
	var buyCarGuide = buyCar[gid];
	//遍历购物车，查看商品是否存在（同型号同颜色）
	for (x in buyCarGuide) {
		var jsonObj = buyCarGuide[x];
		if (jsonObj.specSizepr) {
			ysize = jsonObj.specSizepr
		} else {
			ysize = ''
		}
		if (jsonObj.specColorpr) {
			ycolor = jsonObj.specColorpr
		} else {
			ycolor = ''
		}
		if (jsonObj.specModel) {
			ymodel = jsonObj.specModel
		} else {
			ymodel = ''
		}
		if (jsonObj.specSpec) {
			yspec = jsonObj.specSpec
		} else {
			yspec = ''
		}
		///////
		if (color) {
			ccolor = color
		} else {
			ccolor = ''
		}
		if (size) {
			csize = size
		} else {
			csize = ''
		}
		if (models) {
			cmodels = models
		} else {
			cmodels = ''
		}
		if (spec) {
			cspec = spec
		} else {
			cspec = ''
		}
		if (jsonObj.id == id && ysize == csize && ycolor == ccolor && ymodel == cmodels && yspec == cspec) {
			jsonObj['number'] = num;
		}
	}
	//更新本地购物车信息
	localStorage.buyCar = writeDataBuyCar(JSON.stringify(buyCar));
}

//删除商品：从购物车删除商品。重新计算商品总价
function goodsDel(id, gid, size, color, models, spec) {
	buyCar = readDataBuyCar(localStorage.buyCar);
	buyCar = eval('(' + buyCar + ')');
	var buyCarGuide = buyCar[gid];
	//遍历购物车，查看商品是否存在（同型号同颜色）
	for (x in buyCarGuide) {
		var jsonObj = buyCarGuide[x];

		if (jsonObj.specSizepr) {
			ysize = jsonObj.specSizepr
		} else {
			ysize = ''
		}
		if (jsonObj.specColorpr) {
			ycolor = jsonObj.specColorpr
		} else {
			ycolor = ''
		}
		if (jsonObj.specModel) {
			ymodel = jsonObj.specModel
		} else {
			ymodel = ''
		}
		if (jsonObj.specSpec) {
			yspec = jsonObj.specSpec
		} else {
			yspec = ''
		}
		///////
		if (color) {
			ccolor = color
		} else {
			ccolor = ''
		}
		if (size) {
			csize = size
		} else {
			csize = ''
		}
		if (models) {
			cmodels = models
		} else {
			cmodels = ''
		}
		if (spec) {
			cspec = spec
		} else {
			cspec = ''
		}
		if (jsonObj.id == id && ysize == csize && ycolor == ccolor && ymodel == cmodels && yspec == cspec) {
			buyCarGuide.splice(x, 1)
		}
	}
	//更新本地购物车信息
	localStorage.buyCar = writeDataBuyCar(JSON.stringify(buyCar));
}

//获取商品id：删除商品或结算时，获取选中商品的id
//删除购物车下架商品
function XiagoodsDel(id, gid) {
	buyCar = readDataBuyCar(localStorage.buyCar);
	buyCar = eval('(' + buyCar + ')');
	var buyCarGuide = buyCar[gid];
	//遍历购物车，查看商品是否存在（同型号同颜色）
	for (x in buyCarGuide) {
		var jsonObj = buyCarGuide[x];
		if (jsonObj.id == id) {
			buyCarGuide.splice(x, 1)
		}
	}
	//更新本地购物车信息
	localStorage.buyCar = writeDataBuyCar(JSON.stringify(buyCar));
}